from mcp.server.fastmcp import FastMCP

# Create an MCP server for calculator
mcp = FastMCP("Calculator Server")

@mcp.tool()
def add(a: float, b: float) -> str:
    """Add two numbers"""
    try:
        result = a + b
        return f"{result}"
    except Exception as e:
        return f"Error: {str(e)}"

@mcp.tool()
def subtract(a: float, b: float) -> str:
    """Subtract b from a"""
    try:
        result = a - b
        return f"{result}"
    except Exception as e:
        return f"Error: {str(e)}"

@mcp.tool()
def multiply(a: float, b: float) -> str:
    """Multiply two numbers"""
    try:
        result = a * b
        return f"{result}"
    except Exception as e:
        return f"Error: {str(e)}"

@mcp.tool()
def divide(a: float, b: float) -> str:
    """Divide a by b"""
    try:
        if b == 0:
            return "Error: Division by zero is not allowed"
        result = a / b
        return f"{result}"
    except Exception as e:
        return f"Error: {str(e)}"

if __name__ == "__main__":
    mcp.run(transport="stdio")